import { Component, OnInit } from '@angular/core';
import { SearchResult } from '@services/data-types/common.type';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { User } from '@services/data-types/member.type';
import { MemberService } from '@services/member.service';
import { StorageService } from '@services/storage.service';
import { BatchActionsService } from '@store/batch-actions.service';

@Component({
  selector: 'app-wyy-search-panel',
  templateUrl: './wyy-search-panel.component.html',
  styleUrls: ['./wyy-search-panel.component.less']
})
export class WyySearchPanelComponent implements OnInit {
  searchResult: SearchResult;
  user: User;
  constructor(
    private router: Router,
    private messageService: NzMessageService,
    private memberService: MemberService,
    private storageService: StorageService,
    private batchActionsService: BatchActionsService
  ) { }

  ngOnInit() {
    this.getUserInfo();
  }
  // 跳转
  skipToInfo(path: [string, number]) {
    if ((path[0].includes('singer') && !this.user)) {
      this.messageService.create('error', '请先登录');
      return;
    }
    if (!path[1]) {
      return;
    }
    this.router.navigate(path).then();
  }
  private getUserInfo() {
    const userId = this.storageService.getStorage('wyyUserId');
    if (userId) {
      this.batchActionsService.setUserId(userId.toString());
      this.memberService.getUserDetail(userId).subscribe(res => {
        this.user = res;
      });
    }
  }
}
